package com.itheima.tanhua.apiImpl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.tanhua.api.mongodb.MessageApi;
import com.itheima.tanhua.mapper.AnnouncementMapper;
import com.itheima.tanhua.pojo.db.Announcement;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Slf4j
@DubboService
public class MessageApiImpl implements MessageApi  {

    @Autowired
    AnnouncementMapper announcementMapper;


    @Override
    public Page getAllMessgae(Integer page, Integer pagesize) {
        Page<Announcement>ipage=new Page<>(page,pagesize);
        Integer total = announcementMapper.selectCount(new LambdaQueryWrapper<>());
        ipage.setTotal(total);
        Integer pages=0;
        if (pagesize == 0) {
            pages=0;
        }else {
            pages = total / pagesize;
            if (total % pagesize != 0) {
                pages++;
            }
        }
        ipage.setPages(pages);

        return announcementMapper.selectPage(ipage,new LambdaQueryWrapper<>());
    }



}
